package weak_20241227_29.io;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;

/**
 * @author zdl
 * @date 2024/12/28
 */
public class Demo13 {
    public static void main(String[] args) throws IOException {
        //13. 编写一个Java程序，统计一个文本文件中每个单词出现的次数。
        BufferedReader br = new BufferedReader(new FileReader("D:/test/words.txt"));
        HashMap<String,Integer> map = new HashMap<>();
        String len;
        while ((len = br.readLine()) != null){
            String[] split = len.split(",");
            for (String s : split) {
                if (map.containsKey(s)){
                    Integer i = map.get(s);
                    i++;
                    map.put(s,i);
                }else {
                    map.put(s,1);
                }
            }
        }
        System.out.println(map);

    }
}
